Skip to content

Conversation

sujalsalekar
Copy link

Description

This pull request introduces a critical enhancement to the concurrency model of the Yamux stream muxer in py-libp2p. The update addresses a race condition where concurrent read and write operations on the same YamuxStream instance could interleave, resulting in data corruption and unpredictable protocol behavior.

Summary of Changes

  • Introduced a dedicated asynchronous read/write lock (self.rw_lock) to the YamuxStream class.
  • Both the read and write methods are now protected by this lock, ensuring that only one coroutine can access these methods at a time for a given stream.
  • This approach aligns the concurrency safety of Yamux with the existing pattern used in the Mplex stream muxer.

Impact

  • Prevents data races and corruption in Yamux streams.
  • Improves the stability and reliability of all protocols built on top of the stream muxer.
  • Brings the concurrency model of Yamux in line with best practices and other muxer implementations.

@seetadev seetadev closed this Aug 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants